USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_CODEUDOR]    Script Date: 11/24/2011 14:15:11 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_M0002_CODEUDOR]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_M0002_CODEUDOR]
GO

USE [BMIG_Mensual_POST_CADENA]
GO

/****** Object:  StoredProcedure [dbo].[WASP_M0002_CODEUDOR]    Script Date: 11/24/2011 14:15:11 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[WASP_M0002_CODEUDOR] 
AS
BEGIN
    SELECT	p1suc AS suc
			,p1cta AS cta
			,p1oper AS oper
			,MIN(p1ndoc) AS CODEUDOR1
			,MAX(p1ndoc) AS CODEUDOR2
    INTO	[codeudores]
    FROM	[fsr012] (NOLOCK)
    GROUP BY p1cta
			,p1oper
			,p1suc

    UPDATE	codeudores
    SET		CODEUDOR2 = NULL
    WHERE	CODEUDOR1 = CODEUDOR2
END

GO


